{% block sw_entity_many_to_many_select %}
<sw-select-base
    ref="selectBase"
    class="sw-entity-many-to-many-select"
    :is-loading="isLoading"
    v-bind="$attrs"
    @select-expanded="onSelectExpanded"
    @select-collapsed="onSelectCollapsed"
>
    {% block sw_entity_many_to_many_select_base %}
    {% block sw_entity_many_to_many_select_base_selection %}
    <template #sw-select-selection="{ identification, error, disabled, size, expand, collapse }">
        {% block sw_entity_many_to_many_select_base_selection_slot %}
        {% block sw_entity_many_to_many_select_advanced_selection_modal %}
        <component
            :is="advancedSelectionComponent"
            v-if="isAdvancedSelectionActive && isAdvancedSelectionModalVisible"
            :initial-search-term="searchTerm"
            :initial-selection="entityCollection"
            v-bind="advancedSelectionParameters"
            @modal-close="closeAdvancedSelectionModal"
            @selection-submit="onAdvancedSelectionSubmit"
        />
        {% endblock %}

        <sw-select-selection-list
            ref="selectionList"
            :selections="visibleValues"
            :invisible-count="invisibleValueCount"
            value-property="id"
            v-bind="{ size, labelProperty, placeholder, searchTerm, disabled }"
            @total-count-click="paginateDisplayList"
            @item-remove="remove"
            @search-term-change="onSearchTermChange"
        >
            {% block sw_entity_many_to_many_select_base_selection_list %}
            {% block sw_entity_many_to_many_select_base_selection_list_label %}
            <template #label-property="{ item, index, labelProperty, valueProperty }">
                <slot
                    name="selection-label-property"
                    v-bind="{ item, index, labelProperty, valueProperty, getKey}"
                >
                    {{ getKey(item,labelProperty) || getKey(item, `translated.${labelProperty}`) }}
                </slot>
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-selection-list>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_entity_many_to_many_select_base_results %}
    <template #results-list>
        {% block sw_entity_many_to_many_select_base_results_slot %}
        <sw-select-result-list
            ref="swSelectResultList"
            :options="resultCollection"
            :is-loading="isLoading"
            :empty-message="$tc('global.sw-entity-many-to-many-select.messageNoResults', { term: searchTerm }, 0)"
            :focus-el="$refs.selectionList.getFocusEl()"
            @paginate="paginateResult"
            @item-select="addItem"
        >
            {% block sw_entity_many_to_many_select_base_results_list %}
            {% block sw_entity_many_to_many_select_base_results_list_before %}
            <template #before-item-list>
                {% block sw_entity_many_to_many_select_base_results_list_before_advanced_selection %}
                <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
                <div
                    v-if="isAdvancedSelectionActive"
                    class="sw-many-to-many-select-filtering__advanced-selection sw-select-result"
                    @click="openAdvancedSelectionModal"
                >
                    {{ $tc('global.sw-entity-advanced-selection-modal.link') }}
                </div>
                {% endblock %}

                {% block sw_entity_single_select_base_results_list_before_slot %}
                <slot name="before-item-list"></slot>
                {% endblock %}
            </template>
            {% endblock %}

            {% block sw_entity_many_to_many_select_base_results_list_result %}
            <template #result-item="{ item, index }">
                <slot
                    name="result-item"
                    v-bind="{ item, index, labelProperty, valueProperty: 'id', searchTerm, highlightSearchTerm, isSelected, addItem, getKey }"
                >
                    <sw-select-result
                        :selected="isSelected(item)"
                        v-bind="{ item, index }"
                        @item-select="addItem"
                    >
                        {% block sw_entity_many_to_many_select_base_results_list_result_label %}
                        <slot
                            name="result-label-property"
                            v-bind="{ item, index, labelProperty, valueProperty: 'id', searchTerm, highlightSearchTerm, getKey }"
                        >
                            <sw-highlight-text
                                v-if="highlightSearchTerm"
                                :text="getKey(item,labelProperty) || getKey(item, `translated.${labelProperty}`)"
                                :search-term="searchTerm"
                            />
                            <template v-else>
                                {{ getKey(item,labelProperty) || getKey(item, `translated.${labelProperty}`) }}
                            </template>
                        </slot>
                        {% endblock %}
                    </sw-select-result>
                </slot>
            </template>
            {% endblock %}

            {% block sw_entity_many_to_many_select_base_results_list_after %}
            <template #after-item-list>
                <slot name="after-item-list"></slot>
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-result-list>
        {% endblock %}
    </template>
    {% endblock %}
    {% endblock %}

    <template #label>
        <slot name="label"></slot>
    </template>

    <template #hint>
        <slot name="hint"></slot>
    </template>
</sw-select-base>
{% endblock %}
